Completed
Push — master ( 652c21...99e276 )
by greg
10:52 queued 08:59
created

abe-process.js ➔ abeProcess   B

Complexity

Conditions 5
Paths 20

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
nc 20
nop 2
dl 0
loc 22
cc 5
rs 8.6737
1
import process from 'child_process'
2
import fse from 'fs-extra'
3
4
import {
5
  config
6
  ,Plugins
7
} from '../'
8
9
function prepend(value, array) {
10
  var newArray = array.slice(0)
11
  newArray.unshift(value)
12
  return newArray
13
}
14
15
var abeProcess = function(name, args = []) {
16
  args = prepend(`ABE_WEBSITE=${config.root}`, args)
17
  args = prepend(`ABEJS_PATH=${__dirname}/../../../dist`, args)
18
19
  var file = `${__dirname}/../../cli/process/${name}.js`
20
  try {
21
    var stats = fse.statSync(file)
22
    if (stats.isFile()) {
23
      process.fork(file, args)
24
    }
25
  }catch(err) {
26
    try {
27
      file = Plugins.instance.getProcess(name)
28
      stats = fse.statSync(file)
29
      if (stats.isFile()) {
30
        process.fork(file, args)
31
      }
32
    }catch(err) {
33
      console.log('process fork failed')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
34
    }
35
  }
36
}
37
38
export default abeProcess